// 孙子定理 中国剩余定理 模板
#include <cstdio>
typedef long long ll;
int a[20], m[20], n;
ll exgcd(ll a, ll b, ll &x, ll &y) {
  if (b == 0) {
    x = 1, y = 0;
    return a;
  }
  ll d = exgcd(b, a % b, y, x);
  y -= a / b * x;
  return d;
}

ll crt() {
  ll ans = 0, M = 1;
  ll t1, t2;
  for (int i = 1; i <= n; ++i) M *= m[i];
  for (int i = 1; i <= n; ++i) {
    ll Mi = M / m[i];
    exgcd(Mi, m[i], t1, t2);
    ans = (ans + a[i] * Mi % M * t1) % M;
  }
  return (ans % M + M) % M;
}

int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) scanf("%d%d", m + i, a + i);
  printf("%lld", crt());
  return 0;
}
